Skip to content

doc: clarify how fs.Dirent file types are determined#64532

Open
soreavis wants to merge 1 commit into
nodejs:mainfrom
soreavis:doc-fs-dirent-type
Open

doc: clarify how fs.Dirent file types are determined#64532
soreavis wants to merge 1 commit into
nodejs:mainfrom
soreavis:doc-fs-dirent-type

Conversation

@soreavis

Copy link
Copy Markdown

The fs.Dirent docs don't say where entry file types come from — the confusion in #30646, where the type reported on a remotely mounted file system didn't match lstat() and @addaleax suggested documenting that "the type of the entry may be dependent on the file system and operating system". This adds one paragraph to the fs.Dirent class intro: the type of an entry from a directory read is the type reported by the operating system, it may depend on the file system, lstat() is only used as a fallback when the reported type is unknown, and fs.lstat() is the accurate alternative.

Verified against lib/internal/fs/utils.js (getDirent/getDirents fall back to lstat only on UV_DIRENT_UNKNOWN) and src/node_file.cc (the type comes from uv_fs_scandir_next, no stat call). The wording is scoped to directory reads (fs.readdir(), fs.opendir()) because fs.glob() with withFileTypes builds its dirents from lstat() directly.

I used an AI assistant while researching and drafting this change; I've verified the behavior and the wording against the source myself and take full responsibility for it.

Fixes: #30646

The file type of a directory entry returned by fs.readdir() or
fs.opendir() is the type reported by the operating system's directory
listing. Node.js falls back to lstat() only when the reported type is
unknown, and some file systems may report a type that differs from what
lstat() would return. Document this in the fs.Dirent class introduction,
with fs.lstat() as the accurate alternative.

Fixes: nodejs#30646
Signed-off-by: Julian Soreavis <julian.soreavis@gmail.com>
@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. labels Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readdir(p, { withFileTypes: true }) seemingly returns wrong type

2 participants